<?php

class SaveController extends Zend_Controller_Action
{
    public function preDispatch()
    {

        if (!Zend_Auth::getInstance()->getIdentity()) {
            $this->_redirect('/login/');
        }

        $this->_helper->viewRenderer->setNoRender();
        parent::preDispatch();

    }

    public function stockAction()
    {
        $photo = new Zend_Form_Element_File('photo');
        $params = $this->_helper->admin->prepareStockParams($this->_getAllParams(), $photo);
        $mapper = new Application_Model_Mapper(new Application_Model_DbTable_Stock(), new Application_Model_Stock($params));
        $mapper->save();
        $this->_redirect('/admin/stock/');
    }

    public function usefulAction()
    {
        $params = $this->_helper->admin->prepareUsefulParams($this->_getAllParams());
        $mapper = new Application_Model_Mapper(new Application_Model_DbTable_Useful(), new Application_Model_Useful($params));
        $mapper->save();
        $this->_redirect('/admin/useful/');
    }

    public function galleryAction()
    {
        $photo = new Zend_Form_Element_File('photo');
        $params = $this->_helper->admin->prepareGalleryParams($this->_getAllParams(), $photo);
        $mapper = new Application_Model_Mapper(new Application_Model_DbTable_Gallery(), new Application_Model_Photo($params));
        $mapper->save();
        $this->_redirect('/admin/gallery/');
    }

    public function rentAction()
    {
        $photo = new Zend_Form_Element_File('photo');
        $params = $this->_helper->admin->prepareRentParams($this->_getAllParams(), $photo);
        $mapper = new Application_Model_Mapper(new Application_Model_DbTable_Rent(), new Application_Model_Rent($params));
        $mapper->save();
        $this->_redirect('/admin/rent/');
    }

    public function rentcatAction()
    {
        $icon = new Zend_Form_Element_File('icon');
        $params = $this->_helper->admin->prepareRentCategoryParams($this->_getAllParams(), $icon);
        $mapper = new Application_Model_Mapper(new Application_Model_DbTable_RentCategory(), new Application_Model_RentCategory($params));
        $mapper->save();
        $this->_redirect('/admin/rentcat/');
    }

    public function galleryalbumAction()
    {
        $params = $this->_helper->admin->prepareGalleryAlbum($this->_getAllParams());
        $mapper = new Application_Model_Mapper(new Application_Model_DbTable_GalleryAlbums(), new Application_Model_GalleryAlbums($params));
        $mapper->save();
        $this->_redirect('/admin/galleryalbum/');
    }
}